# Create your views here.
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext 
from lab.space.models import LabImageForm, LabFileForm

def space_form(request):
    labimage = None
    labfile = None
    if request.POST:
        labimage_form = LabImageForm(request.POST, request.FILES, instance = labimage)
        labfile_form = LabFileForm(request.POST, request.FILES, instance = labfile)
        #if not labimage_form['image'].errors
        if labimage_form.is_valid():
        	new_labimage = labimage_form.save(commit=False)
        	new_labimage.user = request.user
        	new_labimage.save()
        #if not labfile_form['file'].errors
        if labfile_form.is_valid():
        	new_labfile = labfile_form.save(commit=False)
        	new_labfile.user = request.user
        	new_labfile.save()
            
    labimage_form = LabImageForm(instance = labimage)
    labfile_form = LabFileForm(instance = labfile)

    return render_to_response('space/space_form.html',{'labimage_form':labimage_form, 'labfile_form':labfile_form}, context_instance=RequestContext(request))

